﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    @*<li>
                            <select class="form-control " id="auditStatus" col="auditStatus">
                                <option value="-1">审核状态 </option>
                                <option value="0">待审核 </option>
                                <option value="1">已审核 </option>
                                <option value="9">已退回 </option>
                            </select>
                        </li>*@
                    <li>
                        <select class="form-control " id="region" col="region">
                        </select>
                    </li>
                    <li>
                        关键字：<input id="keywords" col="keywords" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm hidden-xs" id="toolbar">
            <a id="btnEdit" class="btn btn-success disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnAudit" class="btn btn-danger " onclick="showAudit()"><i class="fa fa-check"></i> 审核</a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var auditStatus=@ViewBag.Status;
    $(function () {
        if (auditStatus == 1) {
            $("#btnEdit").hide();
            $("#btnAudit").hide();
        }
        var regionList = top.getDataDict("Region");
        if (regionList) {
            for (var i = 0; i < regionList.length; i++) {
                $('#region').append('<option values="' + regionList[i].DictValue + '">' + regionList[i].DictValue + '</option>');
            }
        }
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/YiDongYuan/MechanicsApply/GetPageListJson")' + '?auditStatus=' + auditStatus;
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'MechanicsId', title: 'MechanicsId', visible: false },
                { field: 'Region', title: '所属县区' },
                { field: 'HuanBaoCode', title: '环保号牌' },
                { field: 'OwnerName', title: '所有人' },
                { field: 'OwnerTel', title: '联系电话' },
                { field: 'JXDJLX', title: '登记类型' },
                { field: 'JXLB', title: '机械类别' },
                { field: 'PFJD', title: '排放阶段' },
                {
                    field: 'AuditStatus', title: '审核状态', formatter: function (value, row, index) {
                        return top.getDataDictValue('AuditStatus', value);
                    } },
                { field: 'AuditUserName', title: '审核人' },
                {
                    field: 'AuditTime', title: '审核时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
            ],
            singleSelect:true,
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/YiDongYuan/MechanicsApply/MechanicsApplyForm")' + '?id=' + id,
            width: '768px',
            height: '550px',
            isFull:true,
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function showAudit() {
         var id = 0,mechanicsId=0;
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
                mechanicsId = selectedRow[0].MechanicsId;
        }
        debugger;
        var AuditStatus = selectedRow[0].AuditStatus;
        if (AuditStatus!=0) {
            ys.alertError('请勿重复审核');
            return;
        }
        ys.openDialog({
            title: '审核',
            content: '@Url.Content("~/YiDongYuan/MechanicsApply/Audit")' + '?id=' + id ,
            width: '800px',
            height: '450px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }
</script>
